<template>
  <div>
    <van-checkbox-group v-model="ids">
      <van-checkbox :name="i.id" v-for='i in ziyuan' :key="i.id">{{ i.NAME }}</van-checkbox>

    </van-checkbox-group>
    <van-button @click="add" round style="background-color: azure">添加</van-button>

  </div>
</template>

<script>
export default {
  name: "add_jszy2",
  data() {
    return {
      ids: [],
      ziyuan: [],
      id: this.$route.query.id

    }
  },
  methods: {
    getjszy() {
      this.$axios.get('/admin/roles').then(res => {
        if (res.data.code == 200) {
          this.ziyuan = res.data.list2
          this.getidlist()
        }
      })
    },
    add() {
      this.$axios.post('/admin/jszy', {'role_id': this.id, 'ids': this.ids}).then(res => {

        if (res.data.code == 200) {
          alert('添加成功')

        }
      })

    },
    getidlist() {
      this.$axios.get('/admin/jszy?id=' + this.id).then(res => {
        if (res.data.code == 200) {
          this.ids = res.data.idlist

        }

      })
    }
  },
  mounted() {
    this.getjszy()

  }
}
</script>

<style scoped>

</style>
